1. Technical Field of the Invention
The present invention relates to computer graphics and in particular, but not exclusively, to the rendering of an image including shadows in a graphics scene generated by a computer.
2. Description of Related Art
The field of computer graphics is a fast changing one, in which trade-offs are made between the quality of the images being produced and the processing power of the computing platform being used. The trade-off becomes even more acute when the images need to be displayed in real-time, for example in the video-gaming industry.
The rendering of an image on a computer screen entails vast amounts of processing. For example, it is necessary to have a so-called “global scene” (also knows as the “world scene”) of the images to be displayed, and which will be hereinafter referred to as the scene. Broadly speaking, a scene can be thought of as a snap-shot or picture of the image to be displayed on the screen at any instant in time. As would be expected, a scene will itself comprise many different objects each having their own geometry. For example, a global scene might be the interior of a particular room in a house. The room might have windows, furniture, a TV, etc. Each object, for example TV, table, window will have a different geometry and will need to be created with the correct dimensions and co-ordinates on the screen in relation to the other images.
These objects are defined in three dimensions (3D), but will be rendered onto a two-dimensional (2D) computer screen. The technique for rendering a 3D object onto a 2D display involves firstly breaking down the 3D object into polygons defined by primitives. A popular primitive used is a triangle having three vertices. Thus, a 3D image can be transformed into a plurality of triangles each being defined by a unique set of vertices where each vertex would typically contain information relating to co-ordinates (x, y, z), color, texture and lighting. It should be understood that a fairly large storage area is needed to accommodate the vertex information.
Broadly speaking, the creation of an image on a computer graphics screen can be thought of as consisting of a geometry stage and a rendering stage. In existing systems, the geometry stage is responsible for transformation and lighting, in which the 3D object is converted into a number of polygons defined by a set of suitable primitives. Consider an interactive computer game where the user controls the motion of his player, as the player moves forward or backward the objects in the frame will need to be transformed so that they appear closer to and further away from the user, respectively.
In the rendering stage the transformed vertices are placed in a frame buffer in digital form. The frame buffer can in fact comprise a number of buffers, for example, a color buffer, depth buffer, stencil buffer, accumulation buffer. The frame buffer needs to be continuously managed and updated as the frame (or scene) changes. In the rendering stage the pixels are drawn and the frame buffer stores lighting, color and intensity information for each pixel that will be enabled. The digital frame data is then converted to an analog signal to be used to provide the final image for the actual 2D computer display.
The lighting of a scene, and of the objects within it, contributes largely to the overall success of the scene when displayed to the user. There are various methods that have been proposed for dealing with lighting.
The so-called “Shadow Map” method is a popular shadowing technique for determining whether surfaces in a scene are in shadow or illuminated (see, FIG. 1). The method is based on the idea of a two-pass rendering of the scene. In a first pass, the scene is rendered from the position of the light source 2. A depth buffer (the so-called classic zbuffer) stores the depth representing the distance to the object 4 closest to the light source 2 for each pixel. The content of the depth buffer is the actual shadow map 6, which is stored.
Then during a second pass the scene is rendered classically from the viewpoint of the camera 8. For this pass, the depth buffer holds as depths distances from the camera. To ensure that polygons are drawn correctly on the screen, each pixel of each polygon as it is considered is depth compared with any pixel already at a corresponding pixel location in the frame buffer. In one such arrangement, the depth buffer is the same size as the frame buffer, and is used to maintain depth data in the form of a depth value for each pixel that has been written to the frame buffer. When a new pixel is being considered, its depth value is compared with the depth value associated with any pixel that has already been written to the frame buffer at the new pixel's location. In the event that the new pixel is behind the old, then it is discarded because it will be obscured. Conversely, if the new pixel is in front of the old, the new pixel's depth value replaces that of the old pixel in the depth-buffer, and color data is retrieved from associated texture memory and written over the old pixel's color data in the frame buffer.
For each rasterized point, its world-space coordinates are generated (if not already stored) and converted into the light coordinate space. Its distance to the light (or depth) is compared with the corresponding depth stored in the shadow map. The result of the comparison will determine if the point is in shadow (P0) or illuminated (P1).
Let us consider the two points P0, P1 viewed from the camera. Using an inverse ModelView transformation, the world coordinates of P0 and P1 can be determined, and then transformed again in the light coordinate system. For each point, its distance to the light is compared to the depth stored in the corresponding pixel of the shadow map:    if the distance to the light is greater than the corresponding depth, the point is in shadow;    if the distance to the light is “near” the corresponding depth, the point is lit; and    the distance to the light cannot be lower than the corresponding depth in theory.
In this example, d1 is the distance between P1 and the light. By construction, the depth of P1 is also equal to d1 and consequently P1 is in the light. In the other case, d0 (the distance between P0 and the light) is greater than d′0 (the depth of P0). Consequently, P0 is in shadow.
However, the disadvantage of the shadow map method is that it only provides information as to whether a point is in light or shadow and does not cater for soft shadows (i.e., differing shadow intensities).
There is a need in the art to allow soft shadows to be rendered, without hugely increasing the processing overhead.